home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 12071 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  47 lines

  1. Path: htsa.htsa.hva.nl!not-for-mail
  2. From: ferdinan@htsa.htsa.hva.nl (Ferdinand de Boevere)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Storing C Functions In An Array?
  5. Date: 28 Mar 1996 21:07:19 +0100
  6. Organization: Hogeschool van Amsterdam, The Netherlands, E.E. & C.S. Dept.
  7. Message-ID: <4jerhn$sc8@oege.htsa.hva.nl>
  8. References: <4jc1u7$5e9@infa.central.susx.ac.uk>
  9. NNTP-Posting-Host: oege.htsa.hva.nl
  10.  
  11. In article <4jc1u7$5e9@infa.central.susx.ac.uk>,
  12. George Rattray <tepd6@central.susx.ac.uk> wrote:
  13. >Can someone help me, I'm trying to store functions in an array at
  14. >compile time. The following functions are defined as
  15.                                            ^^^^^^^^
  16.                                            declared
  17.  
  18. >    struct complex func(struct complex, CHNL);
  19. >
  20. >I want to store them in an array ch[N];
  21.  
  22. Storing functions in an array is not possible.
  23. What you probably mean is storing 'pointers to function'
  24. in an array.
  25.  
  26. >Therefor using the function with an index as 
  27. >
  28. >    ret = ch[0](x,chnl);
  29.  
  30. This is allowed, with a function-pointer at position 0. 
  31.  
  32. More clearly, however, would be:
  33. ret = (*ch[0])(x, chnl);
  34.  
  35. typedef struct complex (*Fp)(struct complex, CHNL);
  36. struct complex foo(struct complex, CHNL);
  37. Fp ch[N];
  38. ch[0] = foo; /* pointer to foo is at position 0 now */
  39.  
  40. >Any help will be most appreciated, Thanks
  41. >
  42. >George
  43. >
  44.  
  45. Ferdinand
  46.  
  47.